package com.zslc.foreignoption.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @description:
 * @author: Gaoyc
 * @date: 2024-06-23 13:09
 **/
@Slf4j
public class ApifyUtil {

    public static List<JSONObject> getTweetData(String tweetDataUrl,String token, String defaultDatasetId) {
        String url = tweetDataUrl.replace("{datasetId}", defaultDatasetId);
//        url = url + "?token=" + token;
        log.info("获取tweetData数据请求开始，url=【{}】", url);
        Map<String, Object> params = new HashMap<>();
        params.put("token", token);
        List<JSONObject> jsonObjects = JSON.parseArray((HttpUtil.get(url, params)), JSONObject.class);
        log.info("获取tweetData数据请求结束，返回结果=【{}】", jsonObjects.size());
        return jsonObjects;
    }
}
